package base_adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZJB on 2018/2/1.
 *
 * @ copyright: iwhere chengdu technology
 */

public abstract class BaseRecyclerViewAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private List<T> datas;
    public BaseRecyclerViewAdapter() {
        this.datas = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return createViewHolder(parent,viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }



    public void addData(List<T> datas){
        this.datas.addAll(datas);
        this.datas = getVerifyData(this.datas);
        notifyDataSetChanged();
    }


    /**
     * data处理层，对data进行验证，处理之后再显示
     * this.datas 添加值的时候 需要调用
     */
    protected List<T> getVerifyData(List<T> datas){
        return datas;
    }

    abstract @Nullable <VH extends RecyclerView.Adapter> VH creatViewHolder(ViewGroup parent,int viewType);
}
